package com.buaa.student.controller;

import com.buaa.student.post.MyList.StepOneUtils;
import com.buaa.student.post.MyList.StepTwoUtils;
import com.buaa.student.post.to.Lists;
import com.buaa.student.service.DakaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.sql.Date;
import java.util.List;

@Controller
public class AutoBackEndDakaController {

    @Autowired
    private DakaService dakaService;

    /**
     * 执行步骤：
     * 1.获取本年级的未打卡的同学名单
     * 2.对本年级未打卡的同学，循环遍历进行打卡
     * 3.同时对未打卡的同学的未打卡信息，尽心录入到未打卡记录表中。
     */
    @GetMapping("/daka/backend")
    public String AutoBackEndDaka() throws Exception {

        //1.取本年级的未打卡的同学名单
        StepOneUtils stepOneUtils = new StepOneUtils();
        List<Lists> list = stepOneUtils.getList();

        //2.对本年级未打卡的同学，循环遍历进行打卡
        StepTwoUtils stepTwoUtils = new StepTwoUtils();
        for (Lists student : list) {
            /**
             * 测试只对我本人进行测试
             */
//            if(student.getXgh().equals("SY1906121")){
//            System.out.println(student.toString());

            //发送后台打卡的请求
            stepTwoUtils.sendDakaPost(student);
            //TODO 1.对该学生录入未打卡记录中
            dakaService.addRecord(student.getRealname(),student.getXgh(),new Date(System.currentTimeMillis()));

//            }
        }


        return "redirect:/index";
    }

    @GetMapping("/daka/auto")
    public String AutoHtml() throws Exception {

        return "autoDaka";
    }




}
